<template id="c-title">
    <div>
        <div class="title-bar">{{ titleForm.title }}</div>
        <el-tabs v-model="cTitleActive">
            <el-tab-pane label="内容设置" name="first" label-position="left">
                <el-form ref="form" :model="titleForm" label-width="80px">
                    <el-form-item label="标题">
                        <el-input v-model="titleForm.content" size="small"></el-input>
                    </el-form-item>
                    <el-form-item label="链接">
                        <div @click="showPage">
                            <el-input v-model="titleForm.link" size="small" :readonly="true"></el-input>
                        </div>
                    </el-form-item>
                </el-form>
            </el-tab-pane>
            <el-tab-pane label="样式设置" name="second">
                <el-form ref="form" :model="titleForm" label-width="80px" label-position="left">
                    <el-form-item label="背景颜色">
                        <el-color-picker v-model="titleForm.bgColor" style="float: right" size="small"></el-color-picker>
                    </el-form-item>
                    <el-form-item label="字体颜色">
                        <el-color-picker v-model="titleForm.fontColor" style="float: right" size="small"></el-color-picker>
                    </el-form-item>
                    <el-form-item label="文字位置">
                        <el-button-group style="float: right">
                            <el-button size="mini" icon="iconfont icon-juzuo" :class="{'primary': titleForm.textAlign == 'left'}" @click="changePosition('left')"></el-button>
                            <el-button size="mini" icon="iconfont icon-juzhong" :class="{'primary': titleForm.textAlign == 'center'}" @click="changePosition('center')"></el-button>
                            <el-button size="mini" icon="iconfont icon-juyouduiqi" :class="{'primary': titleForm.textAlign == 'right'}" @click="changePosition('right')"></el-button>
                        </el-button-group>
                    </el-form-item>
                    <!--<el-form-item label="文本样式">
                        <el-button-group style="float: right">
                            <el-button size="mini" icon="iconfont icon-fontcolormergea" :class="{'primary': titleForm.textStyle == 'normal'}" ></el-button>
                            <el-button size="mini" icon="iconfont icon-jiacu-" :class="{'primary': titleForm.textStyle == 'blob'}" ></el-button>
                            <el-button size="mini" icon="iconfont icon-fontitalics" :class="{'primary': titleForm.textStyle == 'italic'}" ></el-button>
                        </el-button-group>
                    </el-form-item>-->
                    <el-form-item label="背景样式">
                        <el-button-group style="float: right">
                            <el-button size="mini" icon="iconfont icon-checkbox" :class="{'primary': titleForm.bgStyle == 'square'}" @click="changeBg('square')"></el-button>
                            <el-button size="mini" icon="iconfont icon-yuanjiao" :class="{'primary': titleForm.bgStyle == 'circle'}" @click="changeBg('circle')"></el-button>
                        </el-button-group>
                    </el-form-item>
                    <el-form-item label="背景边距">
                        <el-slider
                            v-model="titleForm.bgMargin"
                            input-size="mini"
                            show-input>
                        </el-slider>
                    </el-form-item>
                    <el-form-item label="文本大小">
                        <el-slider
                                v-model="titleForm.fontSize"
                                input-size="mini"
                                show-input>
                        </el-slider>
                    </el-form-item>
                    <el-form-item label="页面间距">
                        <el-slider
                                v-model="titleForm.pageMargin"
                                input-size="mini"
                                show-input>
                        </el-slider>
                    </el-form-item>
                </el-form>
            </el-tab-pane>
        </el-tabs>

        <el-dialog title="" :visible.sync="dialogPageVisible" width="1000px">
            <pages @selected-page="handleSelect" @close-dialog="dialogPageVisible=false"></pages>
        </el-dialog>
    </div>
</template>

<script>
    Vue.component('cTitle', {
        template: '#c-title',
        props: {
            comData: {
                type: Object
            }
        },
        data() {
            return {
                titleForm: {
                    type: 'cTitle',
                    title: '标题', // 标题
                    content: '标题',
                    link: '', // 链接
                    bgColor: '#fff', // 背景色
                    fontColor: '#000', // 字体颜色
                    textAlign: 'left', // 文字位置
                    textStyle: 'normal', // 文字样式
                    bgStyle: 'square', // 背景样式
                    bgMargin: 0, // 背景边距
                    fontSize: 12, // 文本大小
                    pageMargin: 0 // 页面间距
                },
                cTitleActive: 'first',
                dialogPageVisible: false
            }
        },
        computed: {
            componentData() {
                return JSON.parse(JSON.stringify(this.titleForm));
            },
        },
        watch: {
            componentData: {
                handler(newVal, oldVal) {
                    if (!oldVal) {
                        return false;
                    }

                    this.$emit('diy', {type: 'cTitle', form: this.componentData, data: []})
                },
                deep: true
            },
            comData: {
                handler(newVal) {
                    this.titleForm = newVal
                },
                deep: true
            }
        },
        created() {
            if (this.comData) {
                this.titleForm = this.comData
            }
        },
        methods: {
            // 设置位置
            changePosition(type) {
                this.titleForm.textAlign = type
            },
            // 改变背景样式
            changeBg(type) {
                this.titleForm.bgStyle = type
            },
            // 选择地址
            showPage() {
                this.dialogPageVisible = true
            },
            // 选择地址
            handleSelect(row) {
                this.dialogPageVisible = false
                this.titleForm.link = row.path
            }
        }
    })
</script>

<style>

</style>